package com.example;

import java.text.DecimalFormat;

/**
 * Created with IntelliJ IDEA.
 * User: fransvanderlek
 * Date: 6/16/12
 * Time: 12:28 AM
 * To change this template use File | Settings | File Templates.
 */
public class FileSizeFormatter {

    public String format(long byteSize) {

        String sizeUnit = "bytes";
        float size = byteSize;

        if (byteSize > 1000000000) {
            size = size / 1000000000;
            sizeUnit = "Gb";


        } else if (byteSize > 1000000) {
            size = size / 1000000;
            sizeUnit = "MB";

        } else if (byteSize > 1000) {
            size = size / 1000;
            sizeUnit = "Kb";
        }

        return (new DecimalFormat("#.##")).format(size) + " " + sizeUnit;

    }
}
